package com.david.func_test.view

import android.app.Activity
import android.os.Bundle
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
import com.david.func_test.R

class TabTestActivity: Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_tab_test)
        val tabLayout = findViewById<NoScrollTabLayout>(R.id.tablayout)
        val viewpager = findViewById<ViewPager2>(R.id.viewpager)
        tabLayout.setupWithViewPager2(viewpager)

        val tabs = ArrayList<TabBean>()
        tabs.add(TabBean())
        tabs.add(TabBean())
        tabs.add(TabBean())
        tabLayout.setTabs(tabs)

        viewpager.adapter = TabPageAdpater()
    }
    fun test() {
        val titles: java.util.ArrayList<out String?> = java.util.ArrayList<String?>()
    }
}

class TabPageAdpater:RecyclerView.Adapter<TabPageHolder>(){
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TabPageHolder {
        val title = TextView(parent.context)
        title.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)
        return TabPageHolder(title)
    }

    override fun onBindViewHolder(holder: TabPageHolder, position: Int) {
        holder.title.text = "title $position"
    }

    override fun getItemCount(): Int {
        return 3
    }

}

class TabPageHolder(var title: TextView): RecyclerView.ViewHolder(title) {

}